/** @file wlan_11h.h
 *
 *  @brief Interface for the 802.11h wlan_11h module implemented in wlan_11h.c
 *
 *  Driver interface functions and type declarations for the 11h module
 *    implemented in wlan_11h.c.
 *
 *  (c) Copyright 2003-2008, Marvell International Ltd.
 *  All Rights Reserved
 */

#ifndef _WLAN_11H
#define _WLAN_11H



//! Default IBSS DFS recovery interval (in TBTTs); used for adhoc start
#define WLAN_11H_DEFAULT_DFS_RECOVERY_INTERVAL  100

//! Compiler control flag used to add quiet element to adhoc start command */
#define WLAN_11H_ADD_QUIET_ELEMENT              1

//! Default 11h power constraint used to offset the maximum transmit power
#define WLAN_11H_TPC_POWERCONSTRAINT            0

//! 11h TPC Power capability minimum setting, sent in TPC_INFO command to fw
#define WLAN_11H_TPC_POWERCAPABILITY_MIN        5

//! 11h TPC Power capability maximum setting, sent in TPC_INFO command to fw
#define WLAN_11H_TPC_POWERCAPABILITY_MAX        20

//! Regulatory requirement for the duration of a channel availability check
#define WLAN_11H_CHANNEL_AVAIL_CHECK_DURATION   60000  /* in ms */

//! Maximum number of subbands in the IEEEtypes_SupportedChannels_t structure
#define WLAN_11H_MAX_SUBBANDS                   5

//! Maximum number of DFS channels configured in IEEEtypes_IBSS_DFS_t 
#define WLAN_11H_MAX_IBSS_DFS_CHANNELS          25


#pragma pack(1)

/********************************************************************
 **     IEEE IE Type definitions
 *******************************************************************/
//! Map octet of the basic measurment report (7.3.2.22.1)
typedef struct 
{
    UCHAR  BSS             : 1;   //!< At least one valid MPDU received on channel
    UCHAR  OFDM_Preamble   : 1;   //!< OFDM preamble detected on channel
    UCHAR  unidentifiedSig : 1;   //!< Unidentified signal found on channel
    UCHAR  radar           : 1;   //!< Radar detected on channel
    UCHAR  unmeasured      : 1;   //!< Channel is unmeasured
    UCHAR  rsvd5_7         : 3;   //!< Reserved
} MeasRptBasicMap_t;


//!  IEEE Power Constraint element (7.3.2.15)
typedef struct 
{
    UCHAR  elementId;        //!< IEEE Element ID = 32
    UCHAR  len;              //!< Element length after id and len
    UCHAR  localConstraint;  //!< Local power constraint applied to 11d chan info
} IEEEtypes_PowerConstraint_t;


//!  IEEE Power Capability element (7.3.2.16)
typedef struct
{
    UCHAR  elementId;            //!< IEEE Element ID = 33                  
    UCHAR  len;                  //!< Element length after id and len
    CHAR   minTxPowerCapability;  //!< Minimum Transmit power (dBm)
    CHAR   maxTxPowerCapability;  //!< Maximum Transmit power (dBm)
} IEEEtypes_PowerCapability_t;


//!  IEEE TPC Report element (7.3.2.18)
typedef struct 
{
    UCHAR  elementId;   //!< IEEE Element ID = 35
    UCHAR  len;         //!< Element length after id and len
    CHAR   txPower;     //!< Max power used to transmit the TPC Report frame (dBm)
    CHAR   linkmargin;  //!< Link margin when TPC Request received (dB)
} IEEEtypes_TPCReport_t;


//!  IEEE Supported Channel sub-band description (7.3.2.19)
/**  
 *  Sub-band description used in the supported channels element. 
 */
typedef struct
{
    UCHAR  startChan;  //!< Starting channel in the subband
    UCHAR  numChans;   //!< Number of channels in the subband
} IEEEtypes_SupportChan_Subband_t;


//!  IEEE Supported Channel element (7.3.2.19)
/**
 *  Sent in association requests. Details the sub-bands and number
 *    of channels supported in each subband
 */
typedef struct
{
    UCHAR  elementId;   //!< IEEE Element ID = 36
    UCHAR  len;         //!< Element length after id and len
    
    //! Configured sub-bands information in the element
    IEEEtypes_SupportChan_Subband_t subband[WLAN_11H_MAX_SUBBANDS];

} IEEEtypes_SupportedChannels_t;


//!  Channel Switch Announcment element (7.3.2.20)
/**
 *  Sent in action frames and in beacon and probe responses.  Indicates 
 *    new channel, time until channel switch, and whether or not
 *    transmissions are allowed while the switch is pending.
 */
typedef struct
{
    UCHAR  elementId;          //!< IEEE Element ID = 37
    UCHAR  len;                //!< Element length after id and len
    UCHAR  channelSwitchMode;  //!< Mode: 1 indicates STA quiet during switch time
    UCHAR  newChannelNumber;   //!< New channel 
    UCHAR  channelSwitchCount; //!< Nubmer of TBTTS until switch
} IEEEtypes_ChannelSwitchAnn_t;


//!  IEEE Quiet Period Element (7.3.2.23)
/**
 *  Provided in beacons and probe responses.  Indicates times during 
 *    which the STA should not be transmitting data.  Only starting STAs in
 *    an IBSS and APs are allowed to originate a quiet element. 
 */
typedef struct
{
    UCHAR  elementId;     //!< IEEE Element ID = 40
    UCHAR  len;           //!< Element length after id and len
    UCHAR  quietCount;    //!< Number of TBTTs until beacon with the quiet period
    UCHAR  quietPeriod;   //!< Regular quiet period, # of TBTTS between periods
    USHORT quietDuration; //!< Duration of the quiet period in TUs
    USHORT quietOffset;   //!< Offset in TUs from the TBTT for the quiet period
} IEEEtypes_Quiet_t;


//!  IEEE DFS Channel Map field (7.3.2.24)
/**
 *  Used to list supported channels and provide a octet "map" field which 
 *    contains a basic measurement report for that channel in the 
 *    IEEEtypes_IBSS_DFS_t element
 */
typedef struct
{
    UCHAR  channelNumber;         //!< Channel number
    MeasRptBasicMap_t rptMap;  //!< Basic measurement report for the channel
} IEEEtypes_ChannelMap_t;


//!  IEEE IBSS DFS Element (7.3.2.24)
/**
 *  IBSS DFS element included in ad hoc beacons and probe responses.  
 *    Provides information regarding the IBSS DFS Owner as well as the
 *    originating STAs supported channels and basic measurement results.
 */
typedef struct
{
    UCHAR  elementId;                     //!< IEEE Element ID = 41
    UCHAR  len;                           //!< Element length after id and len
    UCHAR  dfsOwner[6];                   //!< DFS Owner STA Address
    UCHAR  dfsRecoveryInterval;           //!< DFS Recovery time in TBTTs

    //! Variable length map field, one Map entry for each supported channel
    IEEEtypes_ChannelMap_t channelMap[WLAN_11H_MAX_IBSS_DFS_CHANNELS];

} IEEEtypes_IBSS_DFS_t;

#pragma pack()


/********************************************************************
 **     Internal 802.11h Data Structure
 *******************************************************************/
//! 802.11h BSS information kept for each BSSID received in scan results
/**
 * IEEE BSS information needed from scan results for later processing in
 *    join commands 
 */
typedef struct
{
    UCHAR sensed11h;      //!< Capability bit set or 11h IE found in this BSS

    IEEEtypes_PowerConstraint_t powerConstraint;  //!< Power Constraint IE
    IEEEtypes_PowerCapability_t powerCapability;  //!< Power Capability IE
    IEEEtypes_TPCReport_t tpcReport;              //!< TPC Report IE
    IEEEtypes_Quiet_t quiet;                      //!< Quiet IE
    IEEEtypes_IBSS_DFS_t ibssDfs;                 //!< IBSS DFS Element IE
} wlan_11h_bss_info_t;


//! 802.11h State information kept in the wlan_adapter class for the driver
typedef struct
{
    int  is11hEnabled;  //!< Enables/disables 11h in the driver (adhoc start)
    int  is11hActive;   //!< Indicates whether 11h is active in the firmware
    int  txDisabled;    //!< Set when driver receives a STOP TX event from fw

    //! Minimum TX Power capability sent to FW for 11h use and fw power control
    CHAR   minTxPowerCapability;

    //! Maximum TX Power capability sent to FW for 11h use and fw power control
    CHAR   maxTxPowerCapability;

    //! User provisioned local power constraint sent in association requests
    CHAR   usrDefPowerConstraint;

    //! Quiet IE
    IEEEtypes_Quiet_t   quiet_ie;

} wlan_11h_state_t;


//! Data structure used to send a CMD_802_11_TPC_INFO command
typedef struct
{
    UCHAR   Chan;            //!< Channel to which the power constraint applies
    UCHAR   PowerConstraint; //!< Local power constraint to send to firmware
} wlan_11h_tpc_info_param_t;

#endif /*_WLAN_11H */
